//
//  SEGWinningPublicViewModel.m
//  SEGViewModel
//
//  Created by 乔杨 on 2020/6/9.
//

#import "SEGWinningPublicViewModel.h"

@implementation SEGWinningPublicViewModel

- (instancetype)init {
    self = [super init];
    if (self) {
        [self seg_createCommand];
    }
    return self;
}
- (void)seg_createCommand {
    @weakify(self);
    self.command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(NSString *noticeId) {
        @strongify(self);
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            [[MessageRequestModel sharedRequestModel] requestWinningPublicDetailWithObjId:noticeId finished:^(BOOL isSuccessed, id result, NSString *codeType, NSString *errorMessage) {
                if (isSuccessed) {
                    self.winningPublicModel = [MessageRequestModel sharedRequestModel].winningPublicModel;
                    [subscriber sendNext:@""];
                    [subscriber sendCompleted];
                } else {
                    NSError *error = [NSError errorWithDomain:@"" code:0 userInfo:@{NSLocalizedFailureReasonErrorKey:errorMessage}];
                    [subscriber sendError:error];
                }
            }];
            return nil;
        }];
    }];
}

#pragma mark - Getter
- (SEGWinningPublicModel *)winningPublicModel {
    if (!_winningPublicModel) {
        _winningPublicModel = [[SEGWinningPublicModel alloc] init];
    }
    return _winningPublicModel;
}

@end
